<!-- 基础信息 -->
<template>
    <div>
        <el-form label-suffix="：" :label-width="attrs.hasOwnProperty('width')&&attrs.width?attrs.width:'135px'">
            <el-row :gutter="10">
                <el-col v-for="item in label" :span="item.col?item.col:8" :key="item.prop">
                    <el-form-item :label="item.label">
                        <!-- 导师审批的时候可以修改研究方向，需要单独处理 -->
                        <el-row :gutter="20" v-if="editForm&&item.prop==='thesisResearchField'">
                          <el-col :span="18">
                            <el-input v-model="data.thesisResearchField" placeholder="" :maxlength="17"></el-input>
                            <div class="input_tips">{{$t('paperBlindTrial.paperDirectionTips')}}</div>
                          </el-col>
                          <el-col :span="4">
                            <el-button type="primary" size="mini" @click="saveThesisResearch">{{$t('common.btn.save')}}</el-button>
                          </el-col>
                        </el-row>
                        <span v-else-if="!item.type">
                          <el-popover :disabled="data[item.prop] && data[item.prop].length<12" placement="top-start" trigger="hover" :content="data[item.prop]">
                            <div class="label_style" slot="reference">{{data[item.prop]}}</div>
                          </el-popover>
                        </span>
                        <span v-else class="link_style" @click="downloadItem(getFileItem(item.prop))">{{getFileItem(item.prop).attachName}}</span>
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item :label="$t('paperBlindTrial.reviewMsg')" prop="type">
                    <el-form :model="auditForm" ref="auditForm" :rules="rules" label-width="0px">
                      <el-row v-if="!resultState">
                        <el-col :span="6">
                          <el-form-item label="" prop="confirmResField">
                            <el-checkbox :disabled="eidtState" true-label="Y" false-label="N" v-model="auditForm.confirmResField">
                              <i style="color: red;">*</i>{{$t('paperBlindTrial.confirmDirection')}}
                            </el-checkbox>
                          </el-form-item>
                        </el-col>
                        <el-col :span="6">
                          <el-form-item label="" prop="confirmStyleContent">
                            <el-checkbox :disabled="eidtState" true-label="Y" false-label="N" v-model="auditForm.confirmStyleContent">
                              <i style="color: red;">*</i>{{$t('paperBlindTrial.confirmContent')}}
                            </el-checkbox>
                          </el-form-item>
                        </el-col>
                      </el-row>
                      <el-form-item v-else label="" prop="confirmStyle">
                        <el-checkbox :disabled="eidtState" true-label="Y" false-label="N" v-model="auditForm.confirmStyle">
                          <i style="color: red;">*</i>{{$t('paperBlindTrial.confirmPaper')}}
                        </el-checkbox>
                      </el-form-item>
                    </el-form>
                    <el-input v-model="form.symposiumMainPoints" type="textarea" maxlength="100" :rows="3" resize="none" :disabled="eidtState" ></el-input>
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row v-show="!eidtState">
              <el-col :span="5" :offset="19">
                <el-button type="danger" @click="audit('unpass')">{{$t('achievementApply.refuse')}}</el-button>
                <el-button type="primary" @click="audit('pass')">{{$t('achievementApply.agree')}}</el-button>
              </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
import { commonDownload, tutorAuditEdit, tutorAuditConfirm } from "common/src/api/paperBlindTrial";
export default {
    components: {},
    mixins: [],
    props: {
        attrs: {
            type: Object,
            default() {
                return {};
            }
        },
        data: {
            type: Object
        },
        label: {
            type: Array
        },
        // 只有审核可以编辑
        eidtState: {
          type: Boolean,
          default: true
        },
        // 评审结果
        resultState: {
          type: Boolean,
          default: false
        },
        // 研究方向编辑状态，只有导师审核的时候可以编辑
        editForm: {
          type: Boolean,
          default: false
        },
        row: {
          type: Object
        },
        auditFlag: {
          type: Object
        }
    },
    data() {
        return {
          rules: {
            confirmResField: [{ required: true, validator: this.validateCheckBox, trigger: 'change' }],
            confirmStyleContent: [{ required: true, validator: this.validateCheckBox, trigger: 'change' }],
            confirmStyle: [{ required: true, validator: this.validateCheckBox, trigger: 'change' }],
          },
          form: {
            type: '1'
          },
          auditForm: {
            confirmResField: 'N',
            confirmStyleContent: 'N',
            confirmStyle: 'N',
          },
          audits: {
            staus: '',
            msg: '',
          }
        };
    },
    computed: {

    },
    created() {
    },
    mounted() {
      this.form.type = this.resultState ? '2' : '1';
      if (this.eidtState) {
        this.rules = [];
      }
    },
    methods: {
      downloadItem(fileInfo) {
        let fileSuffix = fileInfo.attachName.split('.')[1];
        let fileType = fileSuffix == 'pdf' ? 'application/pdf' : fileSuffix == 'zip' ? 'application/x-zip-compressed' : 'text/plain';
        window.open("/api/designservice/resultPublish/downLoadMore?path=" + fileInfo.attachPath + '&fileName=' + fileInfo.attachName);
        // commonDownload(fileInfo.attachPath, fileInfo.attachName, fileType);
      },
      audit(type) {
        let symposiumMainPoints = this.form.symposiumMainPoints;
        if (symposiumMainPoints && symposiumMainPoints.includes('$')) {
          this.$message.error(this.$t('achievementApply.specilTips'));
          return;
        }
        this.audits = {
          staus: type,
          msg: symposiumMainPoints,
        };
        if (type==='unpass') {
          this.$refs.auditForm.clearValidate();
          this.$emit('emit:complete');
        } else {
          this.$refs.auditForm.validate((valid) => {
            if (valid) {
              // 确认论文研究方向、内容、格式
              let param = !this.resultState ? {
                "id": this.row.applyId,//申请ID，填写详情里面的applyId
                "confirmResField": this.auditForm.confirmResField, //导师确认研究方向（不传是未确认N，管理员角色时忽略该属性）
                "confirmStyleContent": this.auditForm.confirmStyleContent,	//导师确认样式和内容（不传是未确认N，管理员角色时忽略该属性）
              } : {
                "id": this.row.applyId,//申请ID，填写详情里面的applyId
                "confirmStyle": this.auditForm.confirmStyle  //管理员确认论文格式（导师角色时忽略该属性）
              };
              // 确认研究方向、论文格式
              tutorAuditConfirm(param).then(res=> {
                if (res.code == 200) {
                  console.log('确认成功');
                }
              });
              this.form.staus = type;
              this.$emit('emit:complete');
            }
          });
        }
      },
      // 修改论文研究方向
      saveThesisResearch () {
        let researchField = this.data.thesisResearchField;
        if (!researchField || researchField == '') {
          this.$message.error(this.$t('paperBlindTrial.directionTips'));
          return;
        }
        let itemList = researchField.split('；');
        if (researchField.includes('$')) {
          this.$message.error(this.$t('achievementApply.specilTips'));
          return;
        }
        if (itemList.length > 2) {
          this.$message.error(this.$t('paperBlindTrial.twoDirctionTips'));
          return;
        }
        if ((itemList[0] && itemList[0].length > 8) || (itemList[1] && itemList[1].length > 8)) {
          this.$message.error(this.$t('paperBlindTrial.reserachTips'));
          return;
        }
        let param = {
          "id": this.row.applyId,	//申请ID，填写详情里面的applyId
          "thesisResearchField": this.data.thesisResearchField  //研究方向
        };
        tutorAuditEdit(param).then(res=>{
          if (res.code == 200) {
            this.$message.success(this.$t('common.tips.editSuccess'));
          }
        });
      },
      getFileItem(key) {
        let fileItem = this.data.attachList && this.data.attachList.find(v => v.businessType == key);
        return fileItem ? fileItem : {};
      },
      // 校验复选框
      validateCheckBox(rule, value, callback) {
        if (!value || value === '' || value == 'N') {
          return callback(new Error(this.$t('common.pla.pleaseSelect')));
        }
        return callback();
        }
    }
};
</script>

<style scoped lang="scss">
.link_style {
  cursor: pointer;
  color: #3A7FE8;
}
.label_style {
  overflow: hidden;
  text-overflow: ellipsis;
}
.input_tips {
  color: #BDBEBE;
  line-height: 18px;
}
</style>
